<template>
	<view>
		<view class="content">
			<view class="list" v-if="datas.goods.length > 0">
				<view class="pdditem" v-for="(item,index) in datas.goods" :key="index">
					<view class="pdditem_order">
						<view class="pdditem_checked">
							<!-- <checkbox-group @change="shopCheckbox"> -->
							<checkbox @click="shopCheckbox(item)" :value="item.order_sn" :checked="item.checked"
								style="transform:scale(0.8)" />
							<!-- </checkbox-group> -->
							<view class="order">
								<span>订单号：</span>
								<p>{{item.order_sn}}</p>
							</view>
						</view>
						<view class="orderstate">
							<span style="color:#E6A23C">待收货</span>
						</view>
					</view>
					<view class="padditem_waybill">
						<view class="waybill">
							<span>运单号：</span>
							<p>{{item.logistics_sn}}</p>
						</view>
					</view>
					<view class="padditem_shop">
						<view class="shop_details">
							<view class="shop_img">
								<image style="width: 100px; height: 100px;" :src="item.good_img"></image>
							</view>
							<view class="shop_content">
								<view class="shop_title">
									<p>{{item.good_name}}</p>
								</view>
								<view class="shop_items">
									<p>{{item.good_Items}}</p>
								</view>
								<view class="shop_price">
									<p style="color: #409EFF;">￥{{item.good_price}}</p>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>

			<view class="list" v-if="datas.goods.length == 0">
				<view class="noshop_img">
					<image style="width: 30vw; height: 20vw;" src="/static/images/nodata.png"></image>
				</view>
			</view>

			<view class="pddfooter" v-if="datas.goods.length > 0">
				<view class="allchecked">
					<checkbox-group @change="allshopCheckbox">
						<label class="uni-list-cell uni-list-cell-pd">
							<view class="allcheckedbox">
								<checkbox :value="checks" style="transform:scale(0.8)" />
								<view>
									<span
										style="font-weight: bolder !important;font-size: 1.3em !important;color: black;">全选</span>
								</view>
							</view>
						</label>
					</checkbox-group>
				</view>
				<view class="pddbutton">
					<button type="primary"
						style="background-color: red !important;font-weight: bold;width: 22vw; font-size: 1.1em;"
						@click="clickImportshop">导入订单</button>
					<button type="primary"
						style="background-color: black !important;font-weight: bold;margin-left: 4vw; font-size: 1.1em;width: 22vw;display: flex;align-items: center;justify-content: center;"
						@click="clickgotoIndex">返回首页</button>
						<button type="primary"
							style="background-color: black !important;font-weight: bold;margin-left: 4vw; font-size: 1.1em;width: 22vw;display: flex;align-items: center;justify-content: center;"
							@click="clickgotoLogin">重新登录</button>
				</view>
			</view>

			<view class="pddfooter" style="background-color: #f5f5f5;" v-if="datas.goods.length == 0">
				<view class="pddbutton">
					<button type="primary" @click="clickgotoIndex" style="width: 35vw;">返回首页</button>
					<button type="primary" @click="clickgotoLogin" style="width: 35vw;background-color: black !important;margin-left: 10vw;">重新登录</button>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {toolstbupload} from '@/api/exportdata.js';
	export default {
		data() {
			return {
				str: '',
				datas: {},
				checks: 'true'
			}
		},
		onLoad() {
			const longString = uni.getStorageSync('taobaoparamsdata');
			// let datat = JSON.parse(longString)
			let copydata = []
			this.str = longString
			this.datas = JSON.parse(longString)

			uni.removeStorageSync('taobaoparamsdata');


		},
		methods: {
			shopCheckbox(e) {
				// console.log(JSON.stringify(e))
				if (e.checked != undefined) {
					e.checked = !e.checked
				} else {
					e.checked = true
				}
			},
			allshopCheckbox(e) {
				// console.log(JSON.stringify(e)) 
				let itemdata = this.datas.goods
				let values = e.detail.value
				// console.log(values)
				for (let i = 0; i < itemdata.length; i++) {
					let item = itemdata[i]
					if (values.includes('true')) {
						this.$set(item, 'checked', true)
					} else {
						this.$set(item, 'checked', false)
					}
				}

			},
			clickImportshop() {

				let copydatas = JSON.parse(JSON.stringify(this.datas))
				copydatas.goods = []
				let goods = this.datas.goods

				goods.forEach((item) => {
					if (item.checked == true || item.checked == 'true') {
						let copyitem = JSON.parse(JSON.stringify(item))
						delete copyitem.checked;
						copydatas.goods.push(copyitem)
					}
				})

				if (copydatas.goods.length > 0) {
					uni.showLoading({
						title: '加载中...'
					});
					var newgoods = copydatas.goods.map(function(obj) {
						var {
							sellerid,
							...rest
						} = obj;
						return rest;
					});
					// let copygoods = JSON.stringify(copydatas.goods)
					copydatas.goods = JSON.stringify(newgoods)
					// console.log(JSON.stringify(copydatas))
					this.submitForm(copydatas)
				}




			},

			submitForm2(datas) {
				uni.request({
					url: 'http://dhappapi.twkd56.net/index.php/wuliu/Tools/tbupload',
					data: datas,
					header: { // 请求头
						"Content-Type": "application/x-www-form-urlencoded",
					},
					method: 'POST',
					success: (res) => {
						uni.hideLoading();
						// console.log(res)
						if (res.data.status == '200') {
							let msgstr = res.data.msg
							uni.showModal({
								title: '提示',
								content: msgstr,
								showCancel: false,
								success: function(res) {
									if (res.confirm) {
										uni.navigateTo({
											// url: `/pages/pddimport/importstate?state=1&msgdata=${msgstr}`
											url: "/pages/order/order?type=notWarehousing"
										});
									} else if (res.cancel) {
										// console.log('用户点击取消');
									}
								}
							});
						} else {
							uni.showModal({
								title: '提示',
								content: res.data.msg,
								showCancel: false,
								success: function(res) {
									if (res.confirm) {
										console.log('用户点击确定');
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						}
					},
					fail: (err) => {
						console.error(err);

						uni.showModal({
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
					}
				})
			},
			
			async submitForm(datas) {
				try {
					console.log(JSON.stringify(datas))
					let res = await toolstbupload(datas);
					console.log(JSON.stringify(res))
					uni.hideLoading();
					if (res.status == '200') {
						let msgstr = res.msg
						uni.showModal({
							title: '提示',
							content: msgstr,
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									uni.navigateTo({
										// url: `/pages/pddimport/importstate?state=1&msgdata=${msgstr}`
										url: "/pages/order/order?type=notWarehousing"
									});
								} else if (res.cancel) {
									// console.log('用户点击取消');
								}
							}
						});
					} else {
						uni.showModal({
							title: '提示',
							content: res.msg,
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
					}
				} catch (error) {
					uni.showModal({
						title: '提示',
						content: res.msg,
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
			},

			clickgotoIndex() {
				uni.reLaunch({
					url: '/pages/index/index'
				});
			},
			clickgotoLogin() {
				uni.reLaunch({
				    url: '/pages/taobaoimport/taobaoimport?status=1'
				});
			}
			

		},
		mounted() {}
	}
</script>

<style>
	.title-text {
		font-size: 20px !important;
		/* 设置标题文字大小 */
		color: #333 !important;
		/* 设置标题文字颜色 */
	}

	.content {
		font-size: .8em;
		background-color: #f5f5f5;
	}

	.list {
		height: 92vh;
		/* overflow: hidden; */

		overflow-y: auto;
	}

	.pdditem {
		padding: 2vh 3vw;
		background-color: #fff;
		font-size: 1.1em;

	}

	.pdditem:not(:first-child) {
		margin-top: 3vh;
	}

	.pdditem_order {
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1px solid #dcdfe6;
		padding: 1vh 0;
	}

	.pdditem_checked {
		display: flex;
		align-items: center;
	}

	.waybill {
		padding: 1vh 0;
	}

	.order,
	.waybill {
		display: flex;
		align-items: center;
	}

	.shop_details {
		display: flex;
	}

	.shop_content {
		padding-left: 3vw;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.shop_items {
		font-size: .9em;
	}

	.pddfooter {
		width: 96vw;
		padding: 0 2vw;
		position: fixed;
		bottom: 0;
		background-color: #fff;
		height: 8vh;
		display: flex;
		align-items: center;
		justify-content: space-around;

	}

	.pddbutton {
		display: flex;
	}

	/* .pddbutton button {
		height: 4vh;
	} */

	.allcheckedbox {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.noshop_img {
		width: 100vw;
		height: 50vh;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>